package employee;

import java.time.LocalDate;
import java.util.Date;

/**
 * 销售人员员工类
 * 继承自员工类的子类：工资由底薪、月销售额和提成率决定
 * 新增属性：底薪，月销售额，提成率
 */
public class SalesEmployee extends Employee {
    /**
     * 底薪
     */
    private int baseSalary;
    /**
     * 月销售额
     */
    private int monthlySales;
    /**
     * 提成率
     */
    private float commissionRate;

    /**
     * 父类
     * @param id 员工编号
     * @param name 姓名
     * @param dateBirth 出生日期
     * @param dateOnboarding 入职年月
     * 自己
     * @param baseSalary 底薪
     * @param monthlySales 月销售额
     * @param commissionRate 提成率
     */
    public SalesEmployee(int id,
                         String name,
                         Date dateBirth,
                         Date dateOnboarding,
                         int baseSalary,
                         int monthlySales,
                         float commissionRate) {
        super(id, name, dateBirth, dateOnboarding, baseSalary + (int)Math.ceil(monthlySales * monthlySales));
        this.baseSalary = baseSalary;
        this.monthlySales = monthlySales;
        this.commissionRate = commissionRate;
    }

    public int getBaseSalary() {
        return baseSalary;
    }

    public int getMonthlySales() {
        return monthlySales;
    }

    public float getCommissionRate() {
        return commissionRate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof SalesEmployee)) return false;
        if (!super.equals(o)) return false;

        SalesEmployee that = (SalesEmployee) o;

        if (getBaseSalary() != that.getBaseSalary()) return false;
        if (getMonthlySales() != that.getMonthlySales()) return false;
        return Float.compare(that.getCommissionRate(), getCommissionRate()) == 0;

    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + getBaseSalary();
        result = 31 * result + getMonthlySales();
        result = 31 * result + (getCommissionRate() != +0.0f ? Float.floatToIntBits(getCommissionRate()) : 0);
        return result;
    }

    @Override
    public String toString() {
        return "SalesEmployee{" +
                "baseSalary=" + baseSalary +
                ", monthlySales=" + monthlySales +
                ", commissionRate=" + commissionRate +
                "，id=" + id +
                ", name='" + name + '\'' +
                ", dateBirth=" + dateBirth +
                ", dateOnboarding=" + dateOnboarding +
                ", wages=" + wages +
                ", totalSalary=" + totalSalary +
                '}';
    }
}
